// interceptor.js
import store from "../store";
import {getToken} from "./auth";
import {toast} from "uview-plus";


export const forData = ()=>{
    const whiteList = ['/pages/account_login', '/pages/404']; // 白名单
    let userInfo = store.getters.userInfo

    const path = window.location.hash;
// const path = '/' + currentPage;
    console.log(221111)
// 非白名单且未登录时拦截
    if (!checkAuth(path)) {
        toast('请登录')
        uni.reLaunch({ url: '/pages/account_login' }); // 清空页面栈
    }
    function checkAuth(url) {
        console.log(url)
        console.log(22222)
        const path = url.split('#')[1];
        if (whiteList.includes(path)) return true; // 放行白名单
        return getToken().length > 1 && userInfo && userInfo.userId;
    }
}

